package com.hamster.crmpre.web;

import com.hamster.crmpre.config.LoginInterceptor;
import com.hamster.crmpre.pojo.ChatRecord;
import com.hamster.crmpre.pojo.dto.ImageList;
import com.hamster.crmpre.service.ChatRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 聊天记录的Controller
 * @author Tarry
 * @create 2020/2/13 13:46
 */
@RestController
@RequestMapping("chatRecord")
public class ChatRecordController {
    @Autowired
    private ChatRecordService chatRecordService;

    /**
     * 保存聊天记录截图的url
     * @param customerId 客户的id
     * @param urlList    图片的url 集合
     * @return
     */
    @PostMapping("saveRecord")
    public ResponseEntity<Void> saveRecord(@RequestParam String customerId, @RequestBody List<String> urlList){
        String employeeId = LoginInterceptor.getLoginUser().getUserId();
        chatRecordService.saveRecord(customerId,employeeId,urlList);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询该客户的聊天记录
     * @param customerId 客户id
     * @param soft 排序  asc 升序   desc 降序
     * @return
     */
    @GetMapping("listRecord")
    public ResponseEntity<List<ImageList>> listRecord(@RequestParam String customerId,@RequestParam(required = false) String soft){
        String employeeId = LoginInterceptor.getLoginUser().getUserId();
        List<ImageList> recordList = chatRecordService.listRecord(customerId,employeeId,soft);
        return ResponseEntity.ok(recordList);
    }

    /**
     * 根据 id 删除该截图
     * @param id
     * @return
     */
    @GetMapping("deleteRecord")
    public ResponseEntity<Void> deleteRecord(@RequestParam String id){
        chatRecordService.deleteRecord(id);
        return ResponseEntity.ok().build();
    }




}
